//
//  UITableView+LBRefreshAndMoreTableView.m
//  LJBiddingPlatform
//
//  Created by LINAICAI on 16/3/23.
//  Copyright © 2016年 Do1. All rights reserved.
//

#import "UIScrollView+LBRefreshAndMoreTableView.h"
#import <MJRefresh/MJRefresh.h>
#import "LBMJRefreshNormalHeader.h"
#import "LBMJRefreshAutoNormalFooter.h"
@implementation UIScrollView (LBRefreshAndMoreTableView)
#pragma mark- 主功能方法
- (void)addRefreshAction:(void(^)())refresh loadMoreAction:(void(^)())loadMore{
    if (refresh) {
        self.mj_header = [LBMJRefreshNormalHeader headerWithRefreshingBlock:^{
            refresh();
        }];
    }
    if (loadMore) {
        self.mj_footer = [LBMJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            loadMore();
        }];
        
    }
}
#pragma mark- 结束刷新
- (void)endFreshWithNoMoreData{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.mj_header.state = MJRefreshStateIdle;
        self.mj_footer.state = MJRefreshStateNoMoreData;
    });
}
- (void)endFresh{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.mj_footer.state = MJRefreshStateIdle;
        self.mj_header.state = MJRefreshStateIdle;
    });
}
#pragma mark- 结束加载更多
- (void)endLoadMoreWithNoMoreData{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.mj_header.state = MJRefreshStateIdle;
        self.mj_footer.state = MJRefreshStateNoMoreData;
    });
}
- (void)endLoadMore{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.mj_header.state = MJRefreshStateIdle;
        self.mj_footer.state = MJRefreshStateIdle;
    });
}
#pragma mark- 开始刷新
- (void)begainRefresh{
    if (!self.mj_header) {
        return;
    }
    [self.mj_header beginRefreshing];
}
#pragma mark- 开始加载更多
- (void)begainLoadMore{
    if (!self.mj_footer) {
        return;
    }
    [self.mj_footer beginRefreshing];
}

@end
